<% @page_title = "我发出的消息 | 多背一公斤 - 灾后学校重建计划" -%>

<% content_for :sidebar do -%>
  <h2><%= link_to "看我收到的消息", messages_url %></h2>
<% end -%>

<h1>我发出的消息</h1>
<% form_for :messages, :url => destroy_all_messages_url, :html => {:method => 'delete'} do |f| -%>
<table border="0" cellspacing="0" cellpadding="3" class="left ol" width="98%">
  <tr>
    <th>发给</th>
    <th>主题</th>
    <th>时间</th>
    <th>操作</th>
  </tr>
<% @messages.each_with_index do |msg, index| -%>
  <tr>
    <td><%= msg.sender_name %></td>
    <td><%= link_to msg.title, message_url(msg.id) %></td>
    <td><%= msg.created_at.to_date %></td>
    <td><input name="messages[no_<%= index %>]" type="checkbox" value="<%= msg.id %>" />
        <input name="messages[no_<%= index %>]" type="hidden" value="0" /></td>
  </tr>
<% end -%>
</table>
<p style="text-align:right">
  <a href="javascript:void(0)" onclick="CheckAll(true)">全选</a> 
  <a href="javascript:void(0)" onclick="CheckAll(false)">全取消</a> 
  <%= submit_tag "删除选中的消息" %>
</p>
<% end -%>
<%= will_paginate %>
<script type="text/javascript">/*<![CDATA[*/
    function CheckAll(value) 
    {
        var boxes=document.getElementsByTagName("input");
        for(var i=0; i<boxes.length; i++) {
            if (boxes[i].type=='checkbox') {
                boxes[i].checked=value;
            }
        }
    }
/*]]>*/</script>